package com.shiroha.notification.service;

import com.mybatisflex.core.service.IService;
import com.shiroha.common.event.ServiceEventType;
import com.shiroha.notification.pojo.Notification;

import static com.shiroha.notification.pojo.table.Tables.*;

import java.util.List;
import java.util.Map;
import java.util.UUID;

public interface INotificationService extends IService<Notification> {

    /**
     * 发布通知
     * @param serviceEventType 通知类型
     * @param payload 消息负载
     * @return 发布通知是否成功
     */
    boolean publishNotification(ServiceEventType serviceEventType, Map<String, Object> payload);

    /**
     * 获取用户的所有通知
     * @param userId 用户ID
     * @return 通知列表
     */
    default List<Notification> getAllNotificationsByUserId(UUID userId) {
        return this.list(query().where(NOTIFICATION.USER_ID.eq(userId)));
    }

    /**
     * 已读通知
     * @param userId 用户ID
     * @param notificationId 通知ID
     * @return 是否成功
     */
    default boolean readNotification(UUID userId, Long notificationId) {
        return this.updateChain()
                .set(NOTIFICATION.READ, true)
                .where(NOTIFICATION.ID.eq(notificationId))
                .and(NOTIFICATION.USER_ID.eq(userId))
                .update();
    }
}
